package com.server.dao;

import com.server.pojo.Alarm;
import com.server.pojo.MobileApp;
import com.server.pojo.MobileAppAlarm;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface MobileAppAlarmDao extends JpaRepository<MobileAppAlarm,Integer> {
    @Query("SELECT appa.alarm FROM MobileAppAlarm appa " +
            "WHERE appa.mobileApp = :mobileApp " +
            "ORDER BY appa.alarm.alarmAt DESC")
    List<Alarm> getAlarms(@Param("mobileApp") MobileApp mobileApp,Pageable pageable);


    @Query("SELECT appa.mobileApp FROM MobileAppAlarm appa where appa.alarm = :alarm")
    List<MobileApp> getMobileApps(@Param("alarm")Alarm alarm);

}
